<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/11/13
 * Time: 18:54
 */

class WebStoreController extends BaseController{

    /**
     * @Author:      sqq
     * @DateTime:    2018-11-13 18:55:29
     * @Description: 门店列表
     * @Param: []
     * @link: http://www.activity.com/web/store/storeList
     */
    public function storeList(){
        header("Content-Type: text/html; charset=utf-8");
        header('Access-Control-Allow-Origin:*');	//解决资源跨域问题
        header('Access-Control-Allow-Credentials', 'true');
        header('Access-Control-Allow-Headers', 'X-Requested-With,X_Requested_With');
        header('Access-Control-Allow-Headers', 'X-Requested-With, X_Requested_With');
        header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
        header('Access-Control-Allow-Credentials', 'true');
        $validator = Validator::make(Input::all(),
            array(

            )
        );
        do{
            if($validator->fails()) {
                $response = Lang::get("error.args_error_10000");
                $response["result"]=$validator->messages()->all();
                break;
            }

            //获取当前所有开放的城市
            $city = ResourceCityType::where('status',1)->select('id','name','status')->get();
            if(!is_null($city)){
                //获取当前城市下面的所有有效门店
                foreach($city as $key =>$val){
                    $shops = AhpMaintenanceShops::where('city_id',$val->id)->select('id','cms_shop_id','ahp_shop_name','cms_shop_name','address','tel_phone','longitude','latitude','business_start_time','business_end_time','wash_start_time','wash_end_time','first_image','first_h5_image','thumbnail','show_image')->get();
                    if(!is_null($shops)){
                        foreach($shops as $k => $v){
                            $shops[$k]['url'] = Config::get('store_wechat3.store_wechat3_file_url');
                        }
                    }
                    $val->shops = $shops;
                }
            }

            $response = array(
                'code' => 0,
                'msg' => 'ok',
                'result' => $city
            );
        }while(false);
        Log::info("info", array("system" => "web" ,"event" => "storeList", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

}